﻿
using RpcHelper;
using RpcModular.Model;

namespace RpcModular.Domain
{
    /// <summary>
    /// 用户身份标识领域模型
    /// </summary>
    public class IdentityDomain
    {
        private readonly UserIdentity _Identity = null;
        internal IdentityDomain(UserIdentity obj)
        {
            this._Identity = obj;
        }
        /// <summary>
        /// 身份标识ID
        /// </summary>
        public string IdentityId => this._Identity.IdentityId;
        /// <summary>
        /// 身份标识应用名
        /// </summary>
        public string AppName => this._Identity.AppName;

        /// <summary>
        /// 检查请求路径权限
        /// </summary>
        /// <param name="path">请求路径</param>
        /// <exception cref="ErrorException"></exception>
        public void CheckGateway(string path)
        {
            if (!this._Identity.IsValid || !this._Identity.CheckGateway(path))
            {
                throw new ErrorException("Identity.no.prower");
            }
        }

        /// <summary>
        /// 检查服务节点的路由Key权限
        /// </summary>
        /// <param name="msgKey"></param>
        /// <exception cref="ErrorException"></exception>
        internal void CheckRoute(string msgKey)
        {
            if (!this._Identity.IsValid || !this._Identity.CheckRoute(msgKey))
            {
                throw new ErrorException("Identity.no.prower");
            }
        }
    }
}
